﻿using System;
using System.Collections.Generic;
using System.Reflection;
using T.ServiceComponent.Database.Service;
using T.ServiceComponent.I18N.Service;

namespace T.FAS.Runtime.Base.Dao
{
    public class MyBatisDaoFactory<T>: IDaoFactory<T>
    {
        private T instance;

        public T Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = GetDaoInstance();
                }
                return instance;
            }
        }

        public T GetDao()
        {
            return Instance;
        }

        private T GetDaoInstance()
        {
            Type t = typeof(T);
            if (!t.IsInterface)
                throw new Exception($"{TermService.Current.GetTextFormatted("T_FAS_fasr_Base_1401802172", "类型：{0}必须是接口", t)}");
            T dao = DaoService.GetInstance("sqlmap_FAS_Base").GetDao<T>();
            return dao;
        } 
    }
}
